package com.easyexcell.easyexcellexample.controller;

import com.alibaba.fastjson.JSON;
import com.easyexcell.easyexcellexample.dto.QuotationRecordDetailedExportDto;
import com.easyexcell.easyexcellexample.service.EasyExcellExportService;
import com.easyexcell.easyexcellexample.utils.esayexcell.vo.QuotationRecordDetailedVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @User c.c
 * @Since 2023/9/2
 * @Time 18:09
 * @Description
 */
@Controller
public class TestController {
  @Resource
  private EasyExcellExportService easyExcellExportService;


  //导入测试
  @GetMapping("/import")
  public List<QuotationRecordDetailedVo> importExcell(MultipartFile file) {
    List<QuotationRecordDetailedVo> quotationRecordDetailedVos = easyExcellExportService.importQuoteDetailExcell(file);
    return quotationRecordDetailedVos;
  }

  //导出测试
  @GetMapping("/export")
  public void exportExcell(HttpServletResponse response) {

    String json = "[{\"planItemId\":\"3445e724-346b-40f8-9749-c7d3b1b387a8\",\"name\":\"1\",\"code\":\"2\",\"categoryName\":\"物资>工程类物资>钢材\",\"categoryCode\":\"A2,A202,A20201\",\"specification\":\"1\",\"procurementQuantity\":\"1\",\"unit\":\"1\",\"remark\":\"22\",\"taxRate\":\"123211\",\"noTaxUnitPrice\":\"9.99\",\"noTaxAllPrice\":9.99,\"taxUnitPrice\":\"12321\",\"taxAllPrice\":12321,\"currentPrice\":null,\"order\":null,\"taxUnit\":\"12321\",\"noTaxTotal\":9.99},{\"planItemId\":\"0517eac2-1a9a-4d33-9221-239aa81fda18\",\"name\":\"2\",\"code\":\"455\",\"categoryName\":\"工程>工程>工程施工\",\"categoryCode\":\"A1,A101,A10101\",\"specification\":\"2\",\"procurementQuantity\":\"2\",\"unit\":\"3\",\"remark\":\"33\",\"taxRate\":\"1233121\",\"noTaxUnitPrice\":\"0.10\",\"noTaxAllPrice\":0.2,\"taxUnitPrice\":\"1221\",\"taxAllPrice\":2442,\"currentPrice\":null,\"order\":null,\"taxUnit\":\"1221\",\"noTaxTotal\":0.2},{\"planItemId\":\"c3e22366-dce4-48d9-86e3-2f7c2c95f5bc\",\"name\":\"4\",\"code\":\"1\",\"categoryName\":\"物资>工程类物资>钢材\",\"categoryCode\":\"A2,A202,A20201\",\"specification\":\"4\",\"procurementQuantity\":\"5\",\"unit\":\"2\",\"remark\":\"44\",\"taxRate\":\"312321\",\"noTaxUnitPrice\":\"1.00\",\"noTaxAllPrice\":5,\"taxUnitPrice\":\"3123\",\"taxAllPrice\":15615,\"currentPrice\":null,\"order\":null,\"taxUnit\":\"3123\",\"noTaxTotal\":5}]";
    List<QuotationRecordDetailedExportDto> quotationRecordDetailedExportDtos = JSON.parseArray(json, QuotationRecordDetailedExportDto.class);
    easyExcellExportService.exportExcell(quotationRecordDetailedExportDtos, response);
  }
}
